package com.stacktry.funtv.utils;

import android.text.TextUtils;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.funshion.playsdk.register.IAuthCodeGetter;

import java.io.UnsupportedEncodingException;

public class AuthCodeGetter implements IAuthCodeGetter {
    private String authCodeApiUrl;
    public AuthCodeGetter(String authCodeApiUrl){
        this.authCodeApiUrl = authCodeApiUrl;
    }

	@Override
	public void getAuthCode(final AuthCodeCallBack callBack) {
		   HttpUtil.getInstance().sendGetRequest(authCodeApiUrl, new HttpUtil.HttpCallBack() {

            @Override
            public void onSuccess ( HttpResponse httpResponse ) {
                String authCode = JSON.parseObject(new String(httpResponse.content)).getJSONObject("data").getString("auth_code");
                Log.d("authCode",authCode);
                callBack.onSuccess(authCode);
            }
            @Override
            public void onFailer ( int code, String errorMsg ) { 
                callBack.onFail(); 
            }
        });
    }
}


